package com.huarui.task.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import org.ewaf.framework.model.PagingSummary;

import com.huarui.task.model.TaskDetail;
import com.huarui.task.model.TaskListInfo;


public class TaskDetailDao  extends BaseDaoImpl{
	
	public TaskDetail queryById(Integer id , boolean forUpdate){
		Map<String , Object> params = new HashMap<String, Object>();
		params.put("id", id);
		params.put("forUpdate", forUpdate);
		
		return (TaskDetail) getSqlMapClientTemplate().queryForObject(namespace + ".queryById", params);

	}
	
	public TaskDetail  findRollbackTaskDetail(Integer taskId , String status){
		
		Map<String , Object> params = new HashMap<String, Object>();
		params.put("taskId", taskId);
		params.put("status", status);
		params.put("forupdate", true);
		return (TaskDetail) getSqlMapClientTemplate().queryForObject(namespace + ".findRollbackTaskDetail", params);
		
	}

	public TaskDetail findNewTaskDetail(Integer taskId) {
		Map<String , Object> params = new HashMap<String, Object>();
		params.put("taskId", taskId);
		params.put("forUpdate", Boolean.TRUE);
		
		return (TaskDetail) getSqlMapClientTemplate().queryForObject(namespace + ".findNewTaskDetail", params);
		
	}
	
	@SuppressWarnings("unchecked")
	public List<TaskListInfo> findPagingNewTasks(TaskListInfo condition,PagingSummary summary){
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("ownerId", condition.getOwner().getOwnerId());
		params.put("start", summary.getStart());
		params.put("limit", summary.getLimit());
		//logger.info("分页查询的参数==="+params);
		return (List<TaskListInfo>) getSqlMapClientTemplate().queryForList(
				namespace + ".findPagingNewTasks", params);
	}

	public int findNewTaskCount(TaskListInfo condition){
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("ownerId", condition.getOwner().getOwnerId());
		return (Integer) getSqlMapClientTemplate().queryForObject(
				namespace + ".findNewTaskCount", params);
	}

	
	@SuppressWarnings("unchecked")
	public List<TaskDetail> findTaskDetails(Integer taskId){
		return (List<TaskDetail>) getSqlMapClientTemplate().queryForList(namespace + ".findTaskDetails",taskId);
	}
	
	public TaskDetail getLastTaskDetail(Map<String, Object> paramsMap) {
		return (TaskDetail) getSqlMapClientTemplate().queryForObject(super.namespace + ".getLastTaskDetail", paramsMap);
	}
}
